// 企业 服务机构类   ——member表


/******************** 定义类 ***************************************************************/
/*
    管理员类
 */
function Member() {
    this.id = null; // 唯一标识
    this.enterprise_name;//名称
    this.enterprise_profile;//简介
    this.registered_capital;//注册资本
    this.business_licence;//营业执照
    this.business_licence_pic;//营业执照照片
    this.area;//区域
    this.status;//状态
    this.name;//联系人姓名
    this.mobile_phone;//电话
    this.department;//部门
    this.email;//邮箱
    this.member_type = "";// 企业或服务机构类型
    this.create_time = ""; // 注册时间
    this.formated_create_time = ""; // 格式化注册时间
}

// 将对象序列化为一个json对象，可以用于http请求或对象复制
Member.prototype.serialize = function() {
    return {
        id: this.id,
        enterprise_name: this.enterprise_name,
        enterprise_profile: this.enterprise_profile,
        registered_capital: this.registered_capital,
        business_licence: this.business_licence,
        business_licence_pic: this.business_licence_pic,
        area: this.area,
        status: this.status,
        name: this.name,
        mobile_phone: this.mobile_phone,
        department: this.department,
        email: this.email,
        member_type: this.member_type
    }
}

// 用json数据为对象属性赋值
Member.prototype.parse = function(data) {
    this.id = data.id;
    this.enterprise_name=data.enterprise_name;
    this.enterprise_profile=data.enterprise_profile;
    this.registered_capital=data.registered_capital;
    this.business_licence=data.business_licence;
    this.business_licence_pic=data.business_licence_pic;
    this.area=data.area;
    this.status=data.status;
    this.name=data.name;
    this.mobile_phone=data.mobile_phone;
    this.department=data.department;
    this.email=data.email;   
    this.member_type = data.member_type;
    this.create_time = new Date(parseInt(data.create_time)).toLocaleDateString()
}

// 暂时将属性存起来，做一次备份
Member.prototype.storageValue = function() {
    this.storage = this.serialize();
    this.storage.enterprise_name=this.enterprise_name;
    this.storage.enterprise_profile=this.enterprise_profile;
    this.storage.registered_capital=this.registered_capital;
    this.storage.business_licence=this.business_licence;
    this.storage.business_licence_pic=this.business_licence_pic;
    this.storage.area=this.area;
    this.storage.status=this.status;
    this.storage.name=this.name;
    this.storage.mobile_phone=this.mobile_phone;
    this.storage.department=this.department;
    this.storage.email=this.email;
    this.storage.member_type = this.member_type;
}

// 用备份的数据覆盖现有数据
Member.prototype.applyStorageValue = function() {
    if(this.storage) {
        this.parse(this.storage);
    }
}

function permissionStr2Object(str) {
    var result = {};
    var arr;
    arr = str.match(/\+\d+/g);
    if(arr) {
        for(var i = 0, len = arr.length; i < len; i++) {
            if(arr[i].length >= 5) {
                result[arr[i].substring(1)] = true;
            }
        }
    }
    arr = str.match(/\-\d+/g);
    if(arr) {
        for(var i = 0, len = arr.length; i < len; i++) {
            if(arr[i].length >= 5) {
                result[arr[i].substring(1)] = false;
            }
        }
    }
    return result;
}
function permissionObject2Str(obj) {
    var str = "";
    for(var key in obj) {
        str += (obj[key] ? "+" : "-") + key;
    }
    return str;
}

// ******************** 类静态属性与方法 **********************************************
// 解析json数据，返回一个对象
Member.parse = function(data) {
    var o = new Member();
    o.parse(data);
    return o;
}

// 解析json数组，返回对象数组
Member.parseList = function(list) {
    var len = list.length;
    var arr = new Array(len);
    for(var i = 0; i < len; i++) {
        arr[i] = Member.parse(list[i]);
    }
    return arr;
}





// ******************** 导出 **********************************************
export default Member